<?php echo $header;?>
<div class="box">
    <div class="content">
        <h2 class="h2title">File Document</h2>
        <div>
            <div class="warning" style="margin-top:10px;display:none;">
            </div>
            <table style="width:100%;padding:20px;">
                <tr>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">File No</span>
                    </td>
                    <td>
                        <input type="text" id="txtfileno" name="txtfileno" class="txt" maxlength="50"/>
                    </td>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Document No</span>
                    </td>
                    <td>
                        <input type="text" id="txtdocno" name="txtdocno" class="txt" maxlength="50"/>
                    </td>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Filing Date</span>
                    </td>
                    <td>
                        <input type="text" id="txtfilingdate" name="txtfilingdate" class="txt" disabled="true"
						value="<?php echo date('m/d/y'); ?>"/>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Filing Time</span>
                    </td>
                    <td>
                        <input type="text" id="txtfilingtime" name="txtfilingtime" class="txt" maxlength="50"
						 disabled="true" value="<?php echo $stime; ?>"/>
                    </td>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Filed By</span>
                    </td>
                    <td>
                        <input type="text" id="txtfiledby" name="txtfiledby" class="txt" maxlength="50"
						disabled="true" value="<?php echo $this->user->getFirstName(); ?>"/>
                    </td>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Department</span>
                    </td>
                    <td>
                         <select id="seldeptid" disabled="true" class="sel" style="width: 205px;">
                            <option value="">--select--</option>
                            <?php foreach($dept_list as $row){
							$selclass="";
							if($row["department_id"]==$this->user->getDepartmentId()){
							$selclass="selected";
							} 
							?>
                            <option value="<?php echo $row["department_id"]; ?>"
                                <?php echo $selclass;?>
                                >
                                <?php echo $row["name"]; ?>
                            </option>
                            <?php } ?>
                        </select>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
<div class="buttonbar">
    <input type="button" value="Save" id="btnsave" name="btnsave" class="btnradius" style="margin-right:10px;"/><input type="button" value="Reset" id="btnreset" name="btnreset" class="btnradius"/>
</div>
<script type="text/javascript">
    /*
    $("#txtfilingdate").datepicker({
        changeMonth: true,
        changeYear: true
    });
    $('#txtfilingtime').timepicker({
        'timeFormat': 'H:i:s',
        'step': 5
    });
   */
       
    $("#btnsave").click(function(){
        if (validate()) {
            loading("show");
            $.ajax({
                url: "<?php echo MAIN_PAGE.'filedocument/filedocumentpost';?>",
                type: 'POST',
                data: {
                    fileno: $("#txtfileno").val(),
                    docno: $("#txtdocno").val(),
                    filingdate: $("#txtfilingdate").val(),
                    filingtime: $("#txtfilingtime").val(),
                    filedby: $("#txtfiledby").val(),
                    deptid: $("#seldeptid").val()
                },
                dataType: 'json',
                success: function(res){
                    loading('hide');
                    if (res.status) {
                        alert(res.msg);
                        $("#btnreset").trigger("click");
                    }
                    else {
                        alert(res.msg);
                    }
                }
            });
        }
    });
    
    $("#btnreset").click(function(){
        $(".warning").hide();
        var txtarr = ["txtfileno", "txtdocno"];
        for (var i = 0; i < txtarr.length; i++) {
            $("#" + txtarr[i]).val("");
        }
      //  $("#seldeptid option:first").attr('selected', 'selected');
	     var now = new Date();
        $("#txtfilingdate").val(now.format("mm/dd/yy"));
        $("#txtfilingtime").val(now.format("isoTime"));
    });
    
    
    
    function validate(){
        $(".warning").hide();
        if ($("#txtfileno").val() == "") {
            $("#txtfileno").focus();
            $(".warning").text("Please enter File No").show();
            return false;
        }
        if ($("#txtdocno").val() == "") {
            $("#txtdocno").focus();
            $(".warning").text("Please enter Document No").show();
            return false;
        }
        if ($("#txtfilingdate").val() == "") {
            $("#txtfilingdate").focus();
            $(".warning").text("Please enter Filing Date").show();
            return false;
        }
        if ($("#txtfilingtime").val() == "") {
            $("#txtfilingtime").focus();
            $(".warning").text("Please enter Filing Time").show();
            return false;
        }
        if ($("#txtfiledby").val() == "") {
            $("#txtfiledby").focus();
            $(".warning").text("Please enter Filed by").show();
            return false;
        }
        if ($("#seldeptid").val() == "") {
            $("#seldeptid").focus();
            $(".warning").text("Please choose department").show();
            return false;
        }
        return true;
    }
</script>
<?php echo $footer;?>
